package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.DiseaseDao;
import com.itheima.entity.PageResult;
import com.itheima.pojo.Disease;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service(interfaceClass = DiseaseService.class)
@Transactional
public class DiseaseServiceImpl implements DiseaseService {
    @Autowired
    private DiseaseDao diseaseDao;
    //分页查询
    public PageResult findPage(Integer currentPage, Integer pageSize, String queryString) {
        //        如果是条件查询，默认当前页为1，不然在第二页无法查询到
        if(queryString!=null&&!"".equals(queryString)){
            currentPage=1;
        }
        PageHelper.startPage(currentPage,pageSize);
        Page<Disease> page=diseaseDao.findByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    //    新增运动
    public void add(Disease disease) {
        diseaseDao.add(disease);
    }

    //    根据id查找
    public Disease findById(Integer id) {
        return diseaseDao.findById(id);
    }

    //编辑
    public void edit(Disease disease) {
        diseaseDao.edit(disease);
    }

    //    删除
    public void deleteById(Integer id) {
        diseaseDao.deleteById(id);
    }
}
